package org.go.scheduler.database;

import org.go.scheduler.ScheduleBuilder;
import org.go.trigger.Trigger;

public class CalendarIntervalTriggerPersistenceDelegate extends SimplePropertiesTriggerPersistenceDelegateSupport {

	@Override
	protected SimplePropertiesTriggerProperties getTriggerProperties(Trigger trigger) {
		//CalendarIntervalTriggerImpl calTrig = (CalendarIntervalTriggerImpl) trigger;
		Trigger calTrig = trigger;

		SimplePropertiesTriggerProperties props = new SimplePropertiesTriggerProperties();
		props.setInt1(calTrig.getRepeatInterval());
		//props.setString1(calTrig.getRepeatIntervalUnit().name());
		props.setInt2(calTrig.getTimesTriggered());

		return props;
	}

	@Override
	protected TriggerPropertyBundle getTriggerPropertyBundle(SimplePropertiesTriggerProperties props) {

		ScheduleBuilder sb = null;
		//CalendarIntervalScheduleBuilder.calendarIntervalSchedule().withInterval(props.getInt1(), IntervalUnit.valueOf(props.getString1()));

		int timesTriggered = props.getInt2();

		String[] statePropertyNames = { "timesTriggered" };
		Object[] statePropertyValues = { timesTriggered };

		return new TriggerPropertyBundle(sb, statePropertyNames, statePropertyValues);
	}

	@Override
	public boolean canHandleTriggerType(Trigger trigger) {
		return false;
		//((trigger instanceof RepeatTrigger) && !((RepeatTrigger) trigger).hasAdditionalProperties());
	}

	@Override
	public String getHandledTriggerTypeDiscriminator() {
		return TTYPE_CAL_INT;
	}

}
